{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from sklearn import datasets, linear_model,discriminant_analysis,cross_validation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 显示Digit数据\n",
    "def show_digits():\n",
    "    digits = datasets.load_digits()\n",
    "    fig = plt.figure()\n",
    "    #print('images 0 :',digits.data[0])\n",
    "    for i in range(25):\n",
    "        ax = fig.add_subplot(5,5,i+1)\n",
    "        #print(digits.images[i])\n",
    "        ax.imshow(digits.images[i], cmap=plt.cm.gray_r, interpolation='nearest')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVkAAAD8CAYAAADdVNcyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAH+VJREFUeJztnU+MFVX2x7/HnjBx/MMw9kgy/BNHQ2JCGGzCygRJwLiYpN04UTcMm3Zjgqxgx+AKFhNhMwku1E6MMbroGRdEZTKAW7pHiT+NGITuQDNCt8MwJGNC6Nzfggfpd8+3+916Xfe9V6++n8R010m9+259u+6hPKfuORZCgBBCiDzc1+0JCCFEPyMnK4QQGZGTFUKIjMjJCiFERuRkhRAiI3KyQgiRETlZIYTIiJysEEJkJMnJmtnzZnbOzM6b2f7ck6oC0sQjTTjSxVMnTazVji8zGwDwHYCdAC4DOAPg5RDCNwt9ZnBwMDz22GOLjnv9+nVnu3z5srM9/PDDzrZ69eqm44GBgUW/CwAmJycxOztrLU9MIJcmjHPnzjnb3Nycs/3mN79pOv7lL3/ZcuyqanLz5k1n+/77753t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6Zou8zQBtH7uUWWfksXJ3hvcbDxXMd6cY+ck97yrqIs04Wj9eKqoicIFQgiRETlZIYTISG4n+1ZFx85J7nlXURdpwtH68VROk6wxWSGEqDsKFwghREayOFkze97MzpnZeTPbn2H8STP7ysy+NLPxssfPRU5dpMmC41dOF2niqbQmIYRS/wMwAOB7AI8DWAbgLICnSv6OSQCDZc8953+5dZEm/aGLNOk/TXI8yW4FcD6EcCGEcAvABwB8D4j6IV080sQjTTyV1iSHk10F4NK848sNW5lUsZ1wbl2kCadqukgTT6U16Vo92SXSsp1wDZEmHOnikSaebJrkeJKdBrBm3vHqhq00QkI74R4kqy7ShFNBXaSJp9Ka5HCyZwA8aWbrzWwZgJcAfFzW4Gb2gJk9dPd33Gkn/H9ljZ+RbLpIE05FdZEmnkprUnq4IIRw28xeA/Ap7mQF3w4hfF3iV1SynXBmXaQJp3K6SBNP1TXRji8hhMiIdnwJIURG5GSFECIjcrJCCJEROVkhhMiInKwQQmRETlYIITIiJyuEEBmRkxVCiIz8P2NwYhVDk986AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 25 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "show_digits()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载数据方法，这里使用scikit-learn自带的数字识别数据\n",
    "def load_data():\n",
    "    digits = datasets.load_digits()\n",
    "    # stratify参数将按照分类比例进行拆分数据\n",
    "    return cross_validation.train_test_split(digits.data, digits.target,test_size=0.25,random_state=0,stratify=digits.target)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LDA 模型的测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# LDA模型\n",
    "def test_LDA(*data):\n",
    "    train_x,test_x, train_y, test_y = data\n",
    "    lda= discriminant_analysis.LinearDiscriminantAnalysis()\n",
    "    lda.fit(train_x, train_y)\n",
    "\n",
    "    # 成绩\n",
    "    print('【成绩】Testing Score: {0}'.format(lda.score(test_x,test_y)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【成绩】Testing Score: 0.9644444444444444\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.6/site-packages/sklearn/discriminant_analysis.py:388: UserWarning: Variables are collinear.\n",
      "  warnings.warn(\"Variables are collinear.\")\n"
     ]
    }
   ],
   "source": [
    "# 测试\n",
    "train_x,test_x, train_y, test_y = load_data()\n",
    "test_LDA(train_x, test_x, train_y, test_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "# lsqr中引入抖动，相当于正则化项 观察 抖动对预测结果的影响\n",
    "def test_LDA_shrinkage(*data):\n",
    "    train_x,test_x, train_y, test_y = data\n",
    "    shrinkages=np.linspace(0.0,1.0,num=50)\n",
    "    scores=[]\n",
    "    for shrinkage in shrinkages:\n",
    "        lda = discriminant_analysis.LinearDiscriminantAnalysis(solver='lsqr', shrinkage=shrinkage)\n",
    "        lda.fit(train_x, train_y)\n",
    "        scores.append(lda.score(test_x,test_y))\n",
    "    # 绘图：\n",
    "    fig = plt.figure()\n",
    "    ax = fig.add_subplot(111)\n",
    "    ax.plot(shrinkages,scores, label='Testing Score')\n",
    "    ax.set_xlabel(r'shrinkage')\n",
    "    ax.set_ylabel(r'score')\n",
    "    ax.set_ylim(0.9,1.0)\n",
    "    ax.set_title('LDA')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEWCAYAAACXGLsWAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RV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iv4Sd99mZueQuIy0FXgQeN7MLiPRT1LUYnmexPTa80k8/ewDElNO7wo6useaWUMS/4fvA+ZVdK0ixWnWWZFKyszquftWM2sCvAec7O5r465Laia1LEQqr6lmlg1kArcrKCROalmIiEgodXCLiEgohYWIiIRSWIiISCiFhYiIhFJYiIhIqP8HaOwwEtFuTIwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 测试\n",
    "train_x,test_x, train_y, test_y = load_data()\n",
    "test_LDA_shrinkage(train_x, test_x, train_y, test_y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LR模型的测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 逻辑回归模型\n",
    "def test_LR(*data):\n",
    "    train_x,test_x, train_y, test_y = data\n",
    "    regr = linear_model.LogisticRegression()\n",
    "    regr.fit(train_x, train_y)\n",
    "    # 成绩\n",
    "    print('【成绩】Testing Score: {0}'.format(regr.score(test_x,test_y)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【成绩】Testing Score: 0.9488888888888889\n"
     ]
    }
   ],
   "source": [
    "# 测试\n",
    "train_x,test_x, train_y, test_y = load_data()\n",
    "test_LR(train_x, test_x, train_y, test_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 逻辑回归模型 参数C对结果的影响  C是正则化项的倒数，它越小，正则化项越大\n",
    "def test_LR_C(*data):\n",
    "    train_x,test_x, train_y, test_y = data\n",
    "    Cs = np.logspace(-4,4,num=100)\n",
    "    test_score = []\n",
    "    for C in Cs:\n",
    "        regr = linear_model.LogisticRegression(multi_class='multinomial',solver='lbfgs',C=C)\n",
    "        regr.fit(train_x,train_y)\n",
    "        test_score.append(regr.score(test_x,test_y))\n",
    "        \n",
    "    # 绘图：\n",
    "    fig = plt.figure()\n",
    "    ax = fig.add_subplot(111)\n",
    "    ax.plot(Cs,test_score, label='Testing Score')\n",
    "    ax.set_xlabel(r'C')\n",
    "    ax.set_ylabel(r'score')\n",
    "    ax.set_title('LR')\n",
    "    ax.set_xscale('log')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEaCAYAAADg2nttAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl83Hd95/HXR/dtS9bl+5Dt2HLuOAkJJDFOrIbSEgItBNhu6YNttkvTazfbhUdb+th0aVoWtkCh2w00HO0DQja0bGhDkWIndTgCdg4bJJ9SHJ8ajXxJo1ua7/4xh0fnjOT5aa738/HQwzO/32+kj0ea+cz3+nzNOYeIiMhc8lIdgIiIpD8lCxERiUvJQkRE4lKyEBGRuJQsREQkLiULERGJS8lCRETiUrIQSSIzO2Fm9005tsPMgmYWMLN+MztiZr+RqhhFFkLJQmRxnHXOVQBVwB8AXzKza1Ick0jClCxEFpELeQ64AFyf6nhEElWQ6gBEcomZ5QG/BNQCx1McjkjClCxEFscKM7sElBJ63f1n59xrKY5JJGHqhhJZHGedc0sJjVl8HtiZ4nhE5kXJQmQROedGgP8GXGdm7051PCKJUrIQSb5CMyuJfDGlu9c5Nwp8BvhESqITWQDTfhYiyWNmJ4C1Uw7/EFjnnFsVc10ZcBL4DefcdxcvQpGFUbIQEZG41A0lIiJxeZoszOz+cGmD42b2sRnOrzWz3WZ20MxeNLPYZvqnzKzdzA6Z2efNzLyMVUREZudZsjCzf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Zs8554Kpjiv8fZ4FnjWzfwG+cTUxJTM2MzPgL4DvOedeTZe4vDSf+IDTwCrgdRahK3iesXV4Hc9C4jKzQyT5byoZcQEdXrwOkxBXBUl+38rqZDGLlcCpmPungdtnu9g590cAZvZhoPdqn/BkxRVOYu8BioHnPIopYl6xAb8D3AcsMbONzrm/TYe4zGwZ8EngJjP7eDipeGm2+D4PfMHM3skCSy8kwYyxpeA5SiguFu9val5xLfLrMOG4nHOPQHLft3IxWSyIc+6rqY4hlnPuReDFFIcxI+fc5wm9IaYV59x54LfSII4B4DdSHcdM0uU5miqN/6ZeJE1fh5Dc961cnA11Blgdc39V+FiqpWtckL6xpWtcEekcX7rGprjmZ9HiysVksQ/YZGbrzayI0CDQsymOCdI3Lkjf2NI1roh0ji9dY1Nc87N4cXk5ep/qL+CbwDlgjFBf3kfCx38ROEpoFsEfKa70jy1d48qE+NI1NsWVWXGpkKCIiMSVi91QIiIyT0oWIiISl5KFiIjEpWQhIiJxKVmIiEhcShYiIhKXkoWIh8ys0cyeMrNOM3vFzJ4zs82pjktkvlQbSsQj4eq7/wR8zTn3UPjYDUADoUVUIhlDyULEO28HxlxMhVTn3IEUxiOyYOqGEvHOtcArqQ5CJBmULEREJC4lCxHvtAO3pDoIkWRQshDxzh6g2Mwejhwws+vN7K4UxiSyIEoWIh5xoZLODwL3hafOtgOPA92pjUxk/lSiXERE4lLLQkRE4lKyEBGRuJQsREQkLiULERGJS8lCRETiUrIQEZG4lCxERCQuJQsREYnr/wMN9tTj1xeWPwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 进行测试\n",
    "train_x,test_x, train_y, test_y = load_data()\n",
    "test_LR_C(train_x, test_x, train_y, test_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 逻辑回归模型\n",
    "def test_LR2(*data):\n",
    "    train_x,test_x, train_y, test_y = data\n",
    "    regr = linear_model.LogisticRegression(multi_class='multinomial',solver='lbfgs',C=0.02)\n",
    "    regr.fit(train_x, train_y)\n",
    "    # 成绩\n",
    "    print('【成绩】Testing Score: {0}'.format(regr.score(test_x,test_y)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【成绩】Testing Score: 0.9755555555555555\n"
     ]
    }
   ],
   "source": [
    "# 进行测试\n",
    "train_x,test_x, train_y, test_y = load_data()\n",
    "test_LR2(train_x, test_x, train_y, test_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
